package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.LevelRoomTypeMapService;
import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.DataGrid;
import com.the4man.framework.model.LevelRoomTypeMap;
import com.the4man.framework.model.LevelRoomTypeMapExample;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import com.the4man.framework.utils.RequestUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Action(
        value = "levelRoomTypeMapAction",
        results = {@Result(
                name = "addPage",
                location = "/cnbdw/levelRoomTypeMap/add.jsp"
        ), @Result(
                name = "listPage",
                location = "/cnbdw/levelRoomTypeMap/list.jsp"
        ), @Result(
                name = "editPage",
                location = "/cnbdw/levelRoomTypeMap/edit.jsp"
        )}
)
public class LevelRoomTypeMapAction extends BaseAction implements ModelDriven<LevelRoomTypeMap> {
    private LevelRoomTypeMap levelRoomTypeMap = new LevelRoomTypeMap();
    @Autowired
    private LevelRoomTypeMapService levelRoomTypeMapService;

    public LevelRoomTypeMapAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public String toAddPage() {
        return "addPage";
    }

    public String toEditPage() {
        return "editPage";
    }

    public void getAllDatasourceList() {
        try {
            LevelRoomTypeMapExample levelRoomTypeMapExample = new LevelRoomTypeMapExample();
            this.levelRoomTypeMapService.countByExample(levelRoomTypeMapExample);
            Page<LevelRoomTypeMap> page = new Page();
            this.setPageProperties(page);
            this.levelRoomTypeMapService.selectByExample(levelRoomTypeMapExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var5) {
            LOG.error("获取数据失败", var5, new String[0]);
        }

    }

    public void add() {
        PageJson json = new PageJson();

        try {
            Date time = new Date();
            this.levelRoomTypeMap.setCreateTime(time);
            this.levelRoomTypeMap.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
            this.levelRoomTypeMapService.insert(this.levelRoomTypeMap);
            json.setReturnFlag(true);
            json.setReturnMsg("提交成功！");
        } catch (Exception var3) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var3, new String[0]);
        }

        this.writeJson(json);
    }

    public void update() {
        PageJson json = new PageJson();

        try {
            this.levelRoomTypeMapService.updateByPrimaryKey(this.levelRoomTypeMap);
            json.setReturnFlag(true);
            json.setReturnMsg("提交成功！");
        } catch (Exception var3) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var3, new String[0]);
        }

        this.writeJson(json);
    }

    public String executeModifyResult() {
        try {
            Object instance = this.levelRoomTypeMapService.selectByPrimaryKey(this.levelRoomTypeMap.getId(), LevelRoomTypeMap.class);
            this.getRequest().setAttribute("instance", instance);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

        return "modifyPage";
    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            int i = this.levelRoomTypeMapService.deleteByPrimaryKey(this.getRequest().getParameter("ids"), LevelRoomTypeMap.class);
            if(i > 0) {
                json.setReturnMsg("删除LevelRoomTypeMap_info成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("删除LevelRoomTypeMap_info失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var3) {
            LOG.error("批量删除LevelRoomTypeMap_info失败！", var3, new String[0]);
            json.setReturnMsg("删除LevelRoomTypeMap_info失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void verify() {
        PageJson json = new PageJson();
        this.writeJson(json);
    }

    public LevelRoomTypeMap getModel() {
        return this.levelRoomTypeMap;
    }
}
